<template>
  <div class="rated">
    <p class="title">最受好评电影</p>
    <div class="wrapper">
      <ul>
        <li v-for="item in ratedList" :key="item._id">
          <div class="imgwrap">
            <img :src="item.imgUrl" alt="" />
            <div class="score" v-if="item.score">观众评分:{{ item.score }}</div>
            <div class="score" v-else>{{ item.wishNum }}人想看</div>
          </div>

          <h5>{{ item.title }}</h5>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
// import http from "../../utils/http";
import BScroll from "better-scroll";
import { mapState, mapActions } from "vuex";

export default {
  mounted() {
    this.getRatedAsync().then(() => {
      new BScroll(".wrapper", {
        startX: 0,
        scrollX: true,
        scrollY: false,
        click: true,
      });
    });
  },
  // computed: mapState(["ratedList"]),
  computed: mapState({
    ratedList: (state) => state.rated.ratedList,
  }),
  methods: {
    // mapActions可以多加第一个参数是模块名
    ...mapActions("rated", ["getRatedAsync"]),
  },
};
</script>

<style lang="less" scoped>
@import "../../assets/css/var.less";
.rated {
  width: 100%;
  height: 205px;
  background: #fff;
  padding: 12px 15px;

  .title {
    font-size: 14px;
    color: #333;
    margin: 0 0 12px;
  }

  .wrapper {
    overflow: hidden;
  }

  ul {
    // width: 100%;
    height: 150px;
    // 将这个元素变成弹性盒，同时它又是一个行内元素
    display: inline-flex;
    // overflow: auto;

    li {
      width: 85px;
      height: 100%;
      margin-right: 10px;
      flex-shrink: 0;

      .imgwrap {
        width: 85px;
        height: 115px;
        position: relative;
        img {
          width: 100%;
          height: 100%;
        }
        .score {
          position: absolute;
          width: 100%;
          height: 20px;
          left: 0;
          bottom: 0;
          font-size: @xs-font;
          color: @score-color;
          line-height: 20px;
          font-weight: 900;
          background: linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0),
            rgba(0, 0, 0, 0.8)
          );
        }
      }

      h5 {
        font-size: @xs-font;
        width: 100%;
        .ell();
      }
    }
  }
}
</style>
